package com.example.myapplication.app;

import android.app.Application;
import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;

import com.example.myapplication.BuildConfig;
import com.example.myapplication.base.swipebacklayout.BGASwipeBackManager;
import com.example.myapplication.model.buffr.DownInfoDbUtil;
import com.example.myapplication.utils.LogUtils;
import com.example.myapplication.utils.NetworkUtil;
import com.example.myapplication.utils.ToastUtils;

/**
 * 描述:「必须在 Application 的 onCreate 方法中执行 BGASwipeBackManager.getInstance().init(this) 来初始化滑动返回」
 */
public class App extends Application {

    private static App mApplication;

    @Override
    public void onCreate() {
        super.onCreate();
        mApplication = this;
        // 必须在 Application 的 onCreate 方法中执行 BGASwipeBackManager.getInstance().init(this) 来初始化滑动返回
      BGASwipeBackManager.getInstance().init(this);
        LogUtils.logInit(BuildConfig.DEBUG);
        ToastUtils.init(this);
        DownInfoDbUtil.init(mApplication,"net_buffer_db");
        NetworkUtil.init(mApplication,BuildConfig.APPLICATION_ID);
        DownInfoDbUtil.init(mApplication,"net_buffer_db");
    }
    public static App getInstance() {
        return mApplication;
    }
    /**
     * 获取应用的版本号
     *
     * @return 应用版本号，默认返回1
     */
    public static int getAppVersionCode() {
        Context context = getInstance();
        try {
            PackageInfo info = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
            return info.versionCode;
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }
        return 1;
    }
}
